﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Data;

namespace Accounting.Library.GhiSo
{
    public class GhiSoMSP_MuaHangHoa : GhiSoService
    {
        public GhiSoMSP_MuaHangHoa(object ChungTu) : base(ChungTu) { }

        public override void GhiSoChiTiet(ContextManager<Accounting.DataAccess.AccountingDataContext> ctx)
        {
            DataAccess.MSP_MuaHangHoa parent = (DataAccess.MSP_MuaHangHoa)ChungTu;

            //if (!(bool)parent.DaThanhToan)
            //{
                LoaiChungTuId = BusinessConfiguration.Configuration.LoaiChungTuId_MSP_MuaHangHoa;
                NgayChungTu = parent.NgayChungTu;
                NgayHachToan = parent.NgayHachToan;
                SoHD = parent.Ma;

                #region MSP_MuaHangHoa_ChiPhiMuaHang
                foreach (DataAccess.MSP_MuaHangHoa_ChiPhiMuaHang child in parent.MSP_MuaHangHoa_ChiPhiMuaHangs)
                {
                    if (child.SoTienQĐ != null)
                    {
                        if (!child.SoTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.SoTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.CHITIET, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_ChiTiet
                foreach (DataAccess.MSP_MuaHangHoa_ChiTiet child in parent.MSP_MuaHangHoa_ChiTiets)
                {
                    if (child.ThanhTienQĐ != null)
                    {
                        if (!child.ThanhTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TKNoId, child.TKCoId, child.DienGiai, child.ThanhTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.CHITIET, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_ThueNK
                foreach (DataAccess.MSP_MuaHangHoa_ThueNK child in parent.MSP_MuaHangHoa_ThueNKs)
                {
                    if (child.TienThueNKQĐ != null)
                    {
                        if (!child.TienThueNKQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.TienThueNKQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THUE_NK, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_Thue
                foreach (DataAccess.MSP_MuaHangHoa_Thue child in parent.MSP_MuaHangHoa_Thues)
                {
                    if (child.TienThueGTGTQĐ != null)
                    {
                        if (!child.TienThueGTGTQĐ.Equals(0))
                        {
                            SoHD = child.SoHD;
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TKNoId, child.TKCoId, child.DienGiai, child.TienThueGTGTQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THUE_GTGT, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_ThueTTDB
                foreach (DataAccess.MSP_MuaHangHoa_ThueTTDB child in parent.MSP_MuaHangHoa_ThueTTDBs)
                {
                    if (child.TienThueTTDBQĐ != null)
                    {
                        if (!child.TienThueTTDBQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.TienThueTTDBQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THUE_TTDB, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_TSThieuCXL
                foreach (DataAccess.MSP_MuaHangHoa_TSThieuCXL child in parent.MSP_MuaHangHoa_TSThieuCXLs)
                {
                    if (child.SoTienQĐ != null)
                    {
                        if (!child.SoTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.SoTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THIEU_CXL, null, null);
                        }
                    }
                }
                #endregion

                #region MSP_MuaHangHoa_TSThuaCXL
                foreach (DataAccess.MSP_MuaHangHoa_TSThuaCXL child in parent.MSP_MuaHangHoa_TSThuaCXLs)
                {
                    if (child.SoTienQĐ != null)
                    {
                        if (!child.SoTienQĐ.Equals(0))
                        {
                            //Su dung store procedure nay để add dữ liệu vào trong so chi tiet
                            ctx.DataContext.addTH_SoChiTiet(ref Khoa, child.ChungTuGocId, child.Khoa, LoaiChungTuId,
                                NgayChungTu, NgayHachToan, SoHD, child.TkNoId, child.TkCoId, child.DienGiai, child.SoTienQĐ, KyKetChuyenId,
                                BusinessConfiguration.Configuration.THUA_CXL, null, null);
                        }
                    }
                }
                #endregion
            //}
        }
    }
}
